package com.hbyj.struts.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.hbyj.db.function.DbTools;
import com.hbyj.util.Constants;
import com.hbyj.util.PageClass;
import com.opensymphony.xwork2.ActionSupport;


public class YjzyAction extends ActionSupport{
	private String jsonResult;
	private int total;
	private List rows = new ArrayList();
	
	public String getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}

	public String queryZjkForYjzy(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		int pageSize = Constants.PAGE_KEY;
		String name = request.getParameter("name");//查询类型 yapp表示在预案匹配模块中查询
		String conStr = "";
		if(!"".equals(name)){
			name = "%"+name+"%";
			conStr += "and yjcz06055 like '"+name+"'";
		}
		if(!"".equals(conStr)){
			conStr = conStr.substring(4);
			conStr = " where "+conStr;
		}
		String hql = "from YjczYjcz06"+conStr;
		String countHql = "select count(*) from YJCZ_YJCZ06 "+conStr;

		int t = DbTools.getDataSQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(t);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		total = t;
		return SUCCESS;
	}
	
	public String queryYjwzForYjzy(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		int pageSize = Constants.PAGE_KEY;
		String areaCode = request.getParameter("areaCode");
		String zylx = request.getParameter("zylx");
		String zyzt = request.getParameter("zyzt");//
		String conStr = "";
		if(!"".equals(zylx)){
			conStr += " and yjzy01030 ='"+zylx+"' ";
		}
		if(!"".equals(zyzt)){
			conStr += " and yjzy01060 ='"+zyzt+"'";
		}
		String hql = "from YjczYjzy01,Area where areaCode =yjzy01010 and yjzy01010 like '"+areaCode+"'"+conStr;
		String countHql = "select count(*) from YjczYjzy01,Area where areaCode =yjzy01010  and yjzy01010 like '"+areaCode+"'"+conStr;

		int t = DbTools.getDataHQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(t);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		total = t;
		return SUCCESS;
	}
}